<?php
// 通知
class NoticeAction extends BaseAction {

  /**
   * 通知列表
   * @return ajaxObject
   */
  public function noticeList() {
    $conditions['notice_admin_id'] = $_SESSION['trackUser']['admin_id'];
    $currentPage = $this->request['p'] ? $this->request['p'] : 1;

    $data = parent::_modelList('NoticeView', 'notice_id desc', array(), $conditions);
    $dataList = $data['list'] ? $data['list'] : array();

    $ret['list'] = $dataList;
    $ret['pagination']['total'] = intval($data['count']);
    $ret['pagination']['pageSize'] = 10;
    $ret['pagination']['current'] = $currentPage;

    $noticeIds = array();
    foreach ($dataList as $key => $value) {
      $noticeIds[] = $value['notice_id'];
    }

    $updateCon['notice_admin_id'] = $_SESSION['trackUser']['admin_id'];
    M('Notice')->where($updateCon)->save(array('notice_is_read' => 1));

    $this->ajaxReturn($ret, trace(), 1);
  }

  /**
   * 通知列表
   * @return ajaxObject
   */
  public function updateNoticeRead() {
    $saveData['notice_id'] = $this->request['notice_id'];
    $saveData['notice_is_read'] = 1;
    M('Notice')->save($saveData);

    $this->ajaxReturn('', trace(), 1);
  }
}